package cshi.common;


import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

class OneTask extends TimerTask{
	private int id;
	public OneTask(int id) {
		this.id = id;
	}
	
	@Override
	public void run() {
		System.out.println("thread " + id + " running");
		System.gc();//如果没有它，timer执行完了也不会退出
	}
	
}

public class TimerTest {
	public static void testTimer() {
		Timer timer = new Timer();
		timer.schedule(new OneTask(1), 5000);//5秒后启动
		timer.schedule(new OneTask(2), 1000, 3000);//1s后启动，此后每隔3s执行一次
		
		Date date = new Date();
		timer.schedule(new OneTask(3), new Date(date.getTime() + 1000));
		
	}
	public static void main(String[] args){
		testTimer();
	}
}
